var value = [0, 0, 0]; //数据位置下标

var addressList = null;


Page({

  data: {
    myregion: ["北京市", "市辖区", "东城区"],

    transportIndex: 0,

    checked:false
  },
//   头部返回键
    topIcon:function(){
        wx.navigateTo({
          url: '/pages/ff/ff',
        })
    },
  /**

   * 生命周期函数--监听页面加载

   */
  onPullDownRefresh: function () {
    this.onRefresh();
},
  onLoad: function(options) {},
  
  /**

   * 生命周期函数--监听页面显示

   */
  onShow: function() {},
  bindRegionChange:function(e){/* 我的地址 */
    console.log(e)    //查看事件返回值
    this.setData({
        myregion:e.detail.value
    })    //重新复制给myregion
  },
 
  saveAddress: function(e) {/*  bindsubmit */

    var consignee = e.detail.value.consignee;

    var mobile = e.detail.value.mobile;

    var detailAddress = e.detail.value.detailAddress;
    if(consignee==''){
        wx.showToast({
          title: '请输入姓名',
          image:'/image/lian.png'
        })
        return
    }
    else if(mobile==''){
        wx.showToast({
          title: '请输入手机号',
          image:'/image/lian.png'
        })
        return
    }
    else if(detailAddress==''){
        wx.showToast({
          title: '请输入详细地址',
          image:'/image/lian.png'
        })
        return
    }
    else if(mobile.length!=11){
        wx.showToast({
            title: '手机号格式错误',
            image:'/image/lian.png'
          })
          return
    }
    
    var arr = wx.getStorageSync('addressList') || [];
    console.log("arr,{}", arr);
    addressList = {
      consignee: consignee,/* 序号 */
      mobile: mobile,/* 名称 */
      myregion: this.data.myregion,/* 省 */
      detailAddress:detailAddress,/* 详细地址 */
      checked:this.data.checked/* 按钮 */
    }
    arr.push(addressList);
    wx.setStorageSync('addressList', arr);
    wx.navigateBack({
    })

  }

})